/*
 * @Author: your name
 * @Date: 2021-11-16 11:27:50
 * @LastEditTime: 2021-11-16 13:44:24
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /my-react-dome/indexs.ts
 */
type _typeObj = { [anyKey: string]: any }
/**
 * @param copy 深拷贝
 * @param _object 如果不传返回为空对象 必须是js的{}对象
 * @param _obj 可选 返回传入的@param _object 必须是js的{}对象,
 */
export const copy = (_object: _typeObj, _obj: _typeObj = {}): _typeObj => {
    if (!(Object.prototype === Object.getPrototypeOf(_object))) {
        return new Error('传入参数***_object***类型错误')
    }
    for (let key in _object) {
        if (Object.prototype === Object.getPrototypeOf(_object[key])) {
            _obj[key] = copy(_object[key])
        } else {
            _obj[key] = _object[key]
        }
    }
    return _obj
}

const a = {name: '123', title: {name: '123'}}

// const tang = copy(a);
const tang = a;

a.name = 'zhu'

console.log(tang)